package com.fendaren.api.mq;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQSMSConfig {

    public static final String SMS_EXCHANGE = "sms_exchange";
    public static final String SMS_QUEUE = "sms_queue";

    @Bean(SMS_EXCHANGE)
    public Exchange smsExchange() {
        return ExchangeBuilder.topicExchange(SMS_EXCHANGE).durable(true).build();
    }

    @Bean(SMS_QUEUE)
    public Queue queue() {
        return QueueBuilder.durable(SMS_QUEUE).build();
    }

    @Bean
    public Binding binding(@Qualifier(SMS_QUEUE) Queue queue, @Qualifier(SMS_EXCHANGE) Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("fendaren.sms.#").noargs();
    }
}
